#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/12/24 16:24
# @Author  : zzp
# @File    : router
# @Software: PyCharm
from datetime import datetime

from utils import client


class Router(object):
    """ 路由器类 """

    def __init__(self, name):
        self.is_feature = False  # 是否有特征
        self.name = name
        self.neighbors = []  # 路由器的邻居
        self.feature = None
        self.type = 'router'
        self.cache = {}  # 缓存
        self.cache_time = 0  # 缓存时间

    def conn(self, node: client):
        self.neighbors.append(node)

    def set_feature(self, feature):
        self.feature = feature

    def get_feature(self):
        """
        获取路由器特征
        @return:
        """
        return self.feature

    def add_cache(self, id, interface):
        """
        添加缓存
        Args:
            id:
            interface:

        Returns:

        """
        self.cache[id] = interface
        self.cache_time = datetime.now()
        self.cache_size += 1

    def get_cache(self):
        return self.cache
